//
//  MTBeacon123Base.swift
//  MTBLETools
//
//  Created by 方强 on 16/10/24.
//  Copyright © 2016年 MT. All rights reserved.
//

import UIKit
import CoreBluetooth

public class MTBeacon123Base: BLEBase {
    
    public static let SendPowerName = ["A","B","C"];
    
    private var baseCallback = BLEBaseCallback();
    private let requsetOption = BLEBaseAction_ActionOption(timeout: 1000);
    public override init(manager: MTBLEManager) {
        super.init(manager: manager);
        baseCallback.onCharactChanged = onMTSeriCharactChanged;
        baseCallback.onBaseConnect = onMTSeriBaseConnect;
        baseCallback.onDisConnect = onMTSeriBaseDisConnect;
        baseCallback.onManualDisConnect = onMTSeriBaseManualDisConnect;
    }
    
    // 连接
    private var callback:MTBeacon123Base_CallBack!;
    private var pwd:String = "";
    public func connect(mac: String!, pwd:String, callback2: MTBeacon123Base_CallBack, retryTimes: Int) -> ErroCode? {
        MTTools.logout(log: "connect->\(mac)");
        self.callback = callback2;
        self.pwd = pwd;
        connectfail = false;
        return super.connect(mac: mac, callback: baseCallback, retryTimes: retryTimes);
    }
    
    private var workingdevice: MTBLEDevice!;
    public func connect(device: MTBLEDevice!, pwd:String, callback2: MTBeacon123Base_CallBack, retryTime: Int) -> ErroCode? {
        self.callback = callback2;
        self.pwd = pwd;
        self.workingdevice = device;
        connectfail = false;
        return super.connect(device: device, callback: baseCallback, retryTime: retryTime);
    }
    
    // 连接成功回调
    private var connectfail:Bool = false;
    private var connectfail_errocode:ErroCode?;
    private func onMTSeriBaseConnect(ble:BLEBase, erro:ErroCode?){
        MTTools.logout(log: "MTSeriaBase onMTSeriBaseConnect->\(erro?.getMsg())");
        
        if(erro?.getCode() != 0){  // 出错误的情况
            callback.onConnect?(self, erro!);
            return;
        }
        
        discoverServices();
    }
    
    // 获取特定服务
    private static let USER_SERVICE_UUID = "FAE0";
    private static let UUID_CHARACT_UUID = "FAE1";
    private static let MAJOR_CHARACT_UUID = "FAE2";
    private static let MINOR_CHARACT_UUID = "FAE3";
    private static let MEASURED_CHARACT_UUID = "FAE4";
    private static let ATCMD_CHARACT_UUID = "FAE5";
    private var uuid_charact:CBCharacteristic?;
    private var major_charact:CBCharacteristic?;
    private var minor_charact:CBCharacteristic?;
    private var measured_charact:CBCharacteristic?;
    private var atcmd_charact:CBCharacteristic?;

    // 发现服务
    private func discoverServices(){
        
        let action = DiscoverServicesAction(serviceuuids: nil, option: BLEBaseAction_ActionOption(timeout: 4000));
        action.onSuccess = {(action) in
            MTTools.logout(log: "discoverservices onSuccess");
            self.discoverCharacts();
        };
        action.onFail = {(action, errocode) in
            MTTools.logout(log: "discoverservices onFail->\(errocode.getMsg())");
            self.connectfail = true;
            self.connectfail_errocode = errocode;
            super.disConnect();
        };
        super.addNewAction(action: action);  // 等待4秒
    }
    
    // 发现特征值
    private var user_service:CBService?;  // 判断获取到的service是否是需要的
    private func discoverCharacts(){
        
        let services = super.getAllServices();
        if(services == nil){  // 判断是否获取到service
            connectfail = true;
            connectfail_errocode = ErroCode.ERROMAP["getcharacterro"];
            super.disConnect();
            return;
        }
        
        for service in services! {
            if(service.uuid.uuidString == MTBeacon123Base.USER_SERVICE_UUID){
                user_service = service;
                break;
            }
        }
        if(user_service == nil){
            connectfail = true;
            connectfail_errocode = ErroCode.ERROMAP["getcharacterro"];
            super.disConnect();
            return;
        }
        
        var action = DiscoverCharactsAction(service: user_service!, charactuuids: nil, option: BLEBaseAction_ActionOption(timeout: 2000));  // 添加发现命令特征值，等待2秒
        action.onSuccess = {(action) in
            MTTools.logout(log: "discoverCharacts onSuccess cmd_service");
            
            self.haveCharacts();
        };
        action.onFail = {(action, errocode) in
            MTTools.logout(log: "discoverCharacts cmd_service onFail->\(errocode.getMsg())");
            self.connectfail = true;
            self.connectfail_errocode = errocode;
            super.disConnect();
        };
        super.addNewAction(action: action);
    }
    
    // 判断是否有需要的特征值
    private func haveCharacts(){
        for charact in (user_service?.characteristics)! {
            if(charact.uuid.uuidString.uppercased() == MTBeacon123Base.UUID_CHARACT_UUID){
                uuid_charact = charact;
            }
            if(charact.uuid.uuidString.uppercased() == MTBeacon123Base.MAJOR_CHARACT_UUID){
                major_charact = charact;
            }
            if(charact.uuid.uuidString.uppercased() == MTBeacon123Base.MINOR_CHARACT_UUID){
                minor_charact = charact;
            }
            if(charact.uuid.uuidString.uppercased() == MTBeacon123Base.MEASURED_CHARACT_UUID){
                measured_charact = charact;
            }
            if(charact.uuid.uuidString.uppercased() == MTBeacon123Base.ATCMD_CHARACT_UUID){
                atcmd_charact = charact;
            }
        }
        
        if ((uuid_charact == nil) || (major_charact == nil) || (minor_charact == nil) || (measured_charact == nil) || (atcmd_charact == nil)) {
            connectfail = true;
            connectfail_errocode = ErroCode.ERROMAP["getcharacterro"];
            super.disConnect();
            return;
        }
        
        enableNotify();
        
    }
    
    // 开启notify
    private func enableNotify(){
        
        let action = SetNotifyAction(charact: atcmd_charact, enable: true, option: BLEBaseAction_ActionOption(timeout: 1000));// 开启notify，等待1秒
        action.onSuccess = {(action) in
            
            self.verifyPwd();
//            self.MTSericonnect = true;       // 连接成功
//            self.callback.onConnect?(self, ErroCode.ERROMAP["OK"]!);
        };
        action.onFail = {(action, erro) in
            MTTools.logout(log: "discoverCharacts atrecv_charact onFail->\(erro.getMsg())");
            self.connectfail = true;
            self.connectfail_errocode = erro;
            super.disConnect();
        };
        
        super.addNewAction(action: action);

        addListCharact(charact: atcmd_charact);     // 添加到监听列表
    }
    
    // 验证密码
    private func verifyPwd(){
        if(workingdevice.getSetlev() == 0){  // 不需要密码，已经连接成功
            self.MTSericonnect = true;       // 连接成功
            self.callback.onConnect?(self, ErroCode.ERROMAP["OK"]!);
            return;
        }
        if(workingdevice.getSetlev() == 1){  // 需要密码验证
            let verifyPwdAction = WriteCharactWithAckAction(sendCharact: atcmd_charact, reviceCharact: atcmd_charact, datas: "AT+PWD[\(pwd)]".data(using: String.Encoding.utf8), option: BLEBaseAction_ActionOption(timeout: 1000));
            
            verifyPwdAction.onReciveDatas = {(action, charact, datas) in
                action.setStatues(statues: BLEBaseAction_ActionStatues.DONE);
                if(datas == nil){
                    return;
                }
                let ackcmd = String(data: datas!, encoding: String.Encoding.utf8);
                print("ackcmd->\(ackcmd)");
                if(ackcmd != "OK+USER\r\n"){
                    super.disConnect();
                    self.callback.onConnect?(self, ErroCode.ERROMAP["pwderro"]!);
                    return;
                }
                self.MTSericonnect = true;       // 连接成功
                self.callback.onConnect?(self, ErroCode.ERROMAP["OK"]!);
                
            };
            verifyPwdAction.onFail = {(action, errocode) in
                super.disConnect();
                self.callback.onConnect?(self, ErroCode.ERROMAP["pwdfail"]!);
            };
            
            super.addNewAction(action: verifyPwdAction);
            
            return;
        }
    }
    
    // 断开回调
    private func onMTSeriBaseDisConnect(ble:BLEBase, erro:ErroCode){
        MTSericonnect = false;
        
        if(connectfail){  // 连接失败的时候，就不要继续回调断开
            connectfail = false;
            callback.onConnect?(self, connectfail_errocode!);
            return;
        }
        
        callback.onDisConnect?(self, erro);
    }
    
    // 主动断开
    private func onMTSeriBaseManualDisConnect(ble:BLEBase, erro:ErroCode){
        
        MTSericonnect = false;
        
        if(connectfail){  // 连接失败的时候，就不要继续回调断开
            connectfail = false;
            callback.onConnect?(self, connectfail_errocode!);
            return;
        }
        
        callback.onManualDisConnect?(self, erro);
    }
    
    // 查看可用连接状态
    private var MTSericonnect = false;
    public func isMTSericonnect() -> Bool{
        return (isConnected() && MTSericonnect);
    }
    
    // 监听到notify
    private func onMTSeriCharactChanged(ble:BLEBase, characteristic:CBCharacteristic, datas:Data?){
        MTTools.logout(log: "onMTSeriCharactChanged");
    }
    
    // 添加写数据操作
    public func addWriteDatasAction(action:WriteCharactAction) -> ErroCode?{
        if(!isMTSericonnect()){
            return ErroCode.ERROMAP["unconnect"];
        }
        return addNewAction(action: action);
    }
    
    // 读取所有参数
    public func readAllInf(device:MTBLEDevice, pwd:String, readinfscallback:MTBeacon123Base_ReadInfsCallBack) -> ErroCode{
        
        let deviceinf = MTBeaconInfModel();
        
        let connectCallback = MTBeacon123Base_CallBack();
        
        connectCallback.onConnect = {(ble, errocode) in
            if(errocode.getCode() != 0){
                readinfscallback.onFail?(ble, errocode);
                return;
            }
            
            // 读取UUID
            let readuuidAction = ReadCharactAction(charact: self.uuid_charact, option: self.requsetOption);
            readuuidAction.onReadDatas = {(action, charact, datas) in
                if ((datas == nil) || (datas!.count < 16)) {
                    return;
                }
                
                let uuid_str = String(format: "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", datas![0],datas![1],datas![2],datas![3],datas![4],datas![5],datas![6],datas![7],datas![8],datas![9],datas![10],datas![11],datas![12],datas![13],datas![14],datas![15]);
                deviceinf.setBeaconUUID(beaconUUID: uuid_str);
            };
            
            readuuidAction.onFail = {(action, errocode) in
                super.disConnect();
                readinfscallback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "readuuiderro"));
            };
            super.addNewAction(action: readuuidAction);
            
            // 读取major
            let readmajorAction = ReadCharactAction(charact: self.major_charact, option: self.requsetOption);
            readmajorAction.onReadDatas = {(action, charact, datas) in
                if((datas == nil) || (datas!.count != 2)){
                    return;
                }
                let major_int = MTTools.convertUint16(hb: datas![1], lb: datas![0]);
                deviceinf.setMajor(major: major_int);
            };
            
            readmajorAction.onFail = {(action, errocode) in
                super.disConnect();
                readinfscallback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "readmajorerro"));
            };
            super.addNewAction(action: readmajorAction);
            
            // 读取minor
            let readminorAction = ReadCharactAction(charact: self.minor_charact, option: self.requsetOption);
            readminorAction.onReadDatas = {(action, charact, datas) in
                if((datas == nil) || (datas!.count != 2)){
                    return;
                }
                let minor_int = MTTools.convertUint16(hb: datas![1], lb: datas![0]);
                deviceinf.setMinor(minor: minor_int);
            };
            
            readminorAction.onFail = {(action, errocode) in
                super.disConnect();
                readinfscallback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "readminorerro"));
            };
            super.addNewAction(action: readminorAction);
            
            // 读取measured
            let readmeasuredAction = ReadCharactAction(charact: self.measured_charact, option: self.requsetOption);
            readmeasuredAction.onReadDatas = {(action, charact, datas) in
                if((datas == nil) || (datas!.count != 1)){
                    return;
                }
                
                deviceinf.setMeasuedPower(measuedPower: 256-Int(datas![0]));
            };
            
            readmeasuredAction.onFail = {(action, errocode) in
                super.disConnect();
                readinfscallback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "readmeasurederro"));
            };
            super.addNewAction(action: readmeasuredAction);
            
            // 读取发射功率
            let readSendPowerAction = WriteCharactWithAckAction(sendCharact: self.atcmd_charact, reviceCharact: self.atcmd_charact, datas: "AT+POWE?".data(using: String.Encoding.utf8), option: self.requsetOption);
            
            readSendPowerAction.onReciveDatas = {(action, charact, datas) in
                action.setStatues(statues: BLEBaseAction_ActionStatues.DONE);
                if(datas!.count < 7){
                    return;
                }
                
                let sendpower = Int(datas![7]) - 0x41;
                deviceinf.setSendpower(sendpower: sendpower);
            };
            readSendPowerAction.onFail = {(action, errocode) in
                super.disConnect();
                readinfscallback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "readsendpowerderro"));
            };
            
            super.addNewAction(action: readSendPowerAction);
            
            // 读取广播频率
            let readSendHzAction = WriteCharactWithAckAction(sendCharact: self.atcmd_charact, reviceCharact: self.atcmd_charact, datas: "AT+ADVI?".data(using: String.Encoding.utf8), option: self.requsetOption);
            
            readSendHzAction.onReciveDatas = {(action, charact, datas) in
                action.setStatues(statues: BLEBaseAction_ActionStatues.DONE);
                if((datas == nil) || (datas!.count < 9)){
                    return;
                }
                
                var str = String(data: datas!, encoding: String.Encoding.utf8)!;
                
                str = str.substring(with: str.index(str.startIndex, offsetBy: 7) ..< str.index(str.endIndex, offsetBy: -1));

                deviceinf.setSendhz(sendhz: Int(str)!);
            };
            readSendHzAction.onFail = {(action, errocode) in
                super.disConnect();
                readinfscallback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "readsendhzderro"));
            };
            super.addNewAction(action: readSendHzAction);
            
            // 读取固件版本号
            let readVersionAction = WriteCharactWithAckAction(sendCharact: self.atcmd_charact, reviceCharact: self.atcmd_charact, datas: "AT+VERS".data(using: String.Encoding.utf8), option: self.requsetOption);
            
            readVersionAction.setReviceCharact(reviceCharact: self.atcmd_charact);
            
            readVersionAction.onReciveDatas = {(action, charact, datas) in
                action.setStatues(statues: BLEBaseAction_ActionStatues.DONE);
                if((datas == nil) || (datas!.count < 5)){
                    return;
                }
                deviceinf.setVersion(version: String(data: datas!, encoding: String.Encoding.utf8)!);
                readinfscallback.onSuccess?(self, deviceinf);
                super.disConnect();
            };
            readVersionAction.onFail = {(action, errocode) in
                super.disConnect();
                readinfscallback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "readversionderro"));
            };
            super.addNewAction(action: readVersionAction);
            
        };
        
        let errocode = self.connect(device: device, pwd: pwd, callback2: connectCallback, retryTime: 2);
        
        return errocode!;
    }
   
    // 设置通用参数major/minor/uuid
    public func setCommParamters(device:MTBLEDevice, pwd:String, deviceinf:MTBeaconInfModel, callback:MTBeacon123Base_BaseCallBack) -> ErroCode{
        let connectCallback = MTBeacon123Base_CallBack();
        
        connectCallback.onConnect = {(ble, errocode) in
            if(errocode.getCode() != 0){
                callback.onFail?(ble, errocode);
                return;
            }
            
            // 设置major
            var d = Data(bytes: [UInt8](arrayLiteral: MTTools.converLoUint16(i: deviceinf.getMajor()), MTTools.converHiUint16(i: deviceinf.getMajor())));
            let writemajorAction = WriteCharactAction(charact: self.major_charact, datas: d, option: self.requsetOption);
            writemajorAction.onFail = {(action, errocode) in
                super.disConnect();
                callback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "setmajorerro"));
            };
            super.addNewAction(action: writemajorAction);
            
            // 设置minor
            d = Data(bytes: [UInt8](arrayLiteral: MTTools.converLoUint16(i: deviceinf.getMinor()), MTTools.converHiUint16(i: deviceinf.getMinor())));
            let writeminorAction = WriteCharactAction(charact: self.minor_charact, datas: d, option: self.requsetOption);
            writeminorAction.onFail = {(action, errocode) in
                super.disConnect();
                callback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "setminorerro"));
            };
            super.addNewAction(action: writeminorAction);
            
            // 设置UUID
            d = MTTools.convertStringToByteArray(str: deviceinf.getBeaconUUID()!)!;
            let writeuuidAction = WriteCharactAction(charact: self.uuid_charact, datas: d, option: self.requsetOption);
            writeuuidAction.onSuccess = {(action) in
                super.disConnect();
                callback.onSuccess?(self);
            };
            writeuuidAction.onFail = {(action, errocode) in
                super.disConnect();
                callback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "setuuiderro"));
            };
            super.addNewAction(action: writeuuidAction);
        };
        
        let errocode = self.connect(device: device, pwd: pwd, callback2: connectCallback, retryTime: 2);
        
        return errocode!;
    }
    
    // 设置所有参数
    public func setAllParamters(device:MTBLEDevice, pwd:String, deviceinf:MTBeaconInfModel, callback:MTBeacon123Base_BaseCallBack) -> ErroCode{
        
        let connectCallback = MTBeacon123Base_CallBack();
        
        connectCallback.onConnect = {(ble, errocode) in
            if(errocode.getCode() != 0){
                callback.onFail?(ble, errocode);
                return;
            }
            
            // 设置major
            var d = Data(bytes: [UInt8](arrayLiteral: MTTools.converLoUint16(i: deviceinf.getMajor()), MTTools.converHiUint16(i: deviceinf.getMajor())));
            let writemajorAction = WriteCharactAction(charact: self.major_charact, datas: d, option: self.requsetOption);
            writemajorAction.onFail = {(action, errocode) in
                super.disConnect();
                callback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "setmajorerro"));
            };
            super.addNewAction(action: writemajorAction);
            
            // 设置minor
            d = Data(bytes: [UInt8](arrayLiteral: MTTools.converLoUint16(i: deviceinf.getMinor()), MTTools.converHiUint16(i: deviceinf.getMinor())));
            let writeminorAction = WriteCharactAction(charact: self.minor_charact, datas: d, option: self.requsetOption);
            writeminorAction.onFail = {(action, errocode) in
                super.disConnect();
                callback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "setminorerro"));
            };
            super.addNewAction(action: writeminorAction);
            
            // 设置UUID
            d = MTTools.convertStringToByteArray(str: deviceinf.getBeaconUUID()!)!;
            let writeuuidAction = WriteCharactAction(charact: self.uuid_charact, datas: d, option: self.requsetOption);
            writeuuidAction.onFail = {(action, errocode) in
                super.disConnect();
                callback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "setuuiderro"));
            };
            super.addNewAction(action: writeuuidAction);
            
            // 设置measured
            d = Data(bytes: [UInt8](arrayLiteral: UInt8(256-deviceinf.getMeasuedPower())));
            let writemeasuredAction = WriteCharactAction(charact: self.measured_charact, datas: d, option: self.requsetOption);
            writemeasuredAction.onFail = {(action, errocode) in
                super.disConnect();
                callback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "setmeasurederro"));
            };
            super.addNewAction(action: writemeasuredAction);
            
            // 设置发射功率
            let setSendpowerAction = WriteCharactWithAckAction(sendCharact: self.atcmd_charact, reviceCharact: self.atcmd_charact, datas: "AT+POWE[\(MTBeacon123Base.SendPowerName[deviceinf.getSendpower()])]".data(using: String.Encoding.utf8), option: self.requsetOption);
            
            setSendpowerAction.onReciveDatas = {(action, charact, datas) in
                action.setStatues(statues: BLEBaseAction_ActionStatues.DONE);
            };
            setSendpowerAction.onFail = {(action, errocode) in
                super.disConnect();
                callback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "setsendpowerderro"));
            };
            super.addNewAction(action: setSendpowerAction);
            
            // 设置密码
            if(deviceinf.getNewpwd() != nil){
                var newpwdcmd:String = "";
                if(deviceinf.getNewpwd()!.lengthOfBytes(using: String.Encoding.utf8) == 0){
                    newpwdcmd = "AT+IBPWD";
                }else{
                    newpwdcmd = "AT+IBPWD[\(deviceinf.getNewpwd()!)]";
                }
                
                let setPwdAction = WriteCharactWithAckAction(sendCharact: self.atcmd_charact, reviceCharact: self.atcmd_charact, datas: newpwdcmd.data(using: String.Encoding.utf8), option: self.requsetOption);
                
                setPwdAction.onReciveDatas = {(action, charact, datas) in
                    action.setStatues(statues: BLEBaseAction_ActionStatues.DONE);
                };
                setPwdAction.onFail = {(action, errocode) in
                    super.disConnect();
                    callback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "setpwderro"));
                };
                super.addNewAction(action: setPwdAction);
            }
            
            // 设置广播频率
            let setSendHzAction = WriteCharactWithAckAction(sendCharact: self.atcmd_charact, reviceCharact: self.atcmd_charact, datas: "AT+ADVI[\(deviceinf.getSendhz())]".data(using: String.Encoding.utf8), option: self.requsetOption);
            
            setSendHzAction.onReciveDatas = {(action, charact, datas) in
                action.setStatues(statues: BLEBaseAction_ActionStatues.DONE);
                callback.onSuccess?(self);
                super.disConnect();
            };
            setSendHzAction.onFail = {(action, errocode) in
                super.disConnect();
                callback.onFail?(self, ErroCode(code: ErroCode.CUSTOMCODE, msg: "setsendhzerro"));
            };
            super.addNewAction(action: setSendHzAction);
            
        };
        
        let errocode = self.connect(device: device, pwd: pwd, callback2: connectCallback, retryTime: 2);
        
        return errocode!;
    }
    
    // 发送AT指令
    public func sendATCMD(device:MTBLEDevice, pwd:String, action: WriteCharactWithAckAction) -> ErroCode{
        let connectCallback = MTBeacon123Base_CallBack();
        
        connectCallback.onConnect = {(ble, errocode) in
            if(errocode.getCode() != 0){
                action.onFail?(action, errocode);
                return;
            }
            
            action.setSendCharact(sendCharact: self.atcmd_charact);
            action.setReviceCharact(reviceCharact: self.atcmd_charact);
            
            super.addNewAction(action: action);
        };
        
        let errocode = self.connect(device: device, pwd: pwd, callback2: connectCallback, retryTime: 2);
        
        return errocode!;
    }
}

// 回调
public class MTBeacon123Base_CallBack: NSObject {
    public override init() {
        super.init();
    }
    
    public var onConnect:((MTBeacon123Base , ErroCode)->Void)?;
    
    public var reTryConnect:((MTBeacon123Base, Int)->Void)?;
    
    public var onDisConnect:((MTBeacon123Base, ErroCode)->Void)?;
    
    public var onManualDisConnect:((MTBeacon123Base, ErroCode)->Void)?;
    
    public var onDatasRecive:((MTBeacon123Base, CBCharacteristic)->Void)?;
}

// 读取数据回调
public class MTBeacon123Base_ReadInfsCallBack: NSObject{
    public override init() {
        super.init();
    }
    
    public var onSuccess:((MTBeacon123Base, MTBeaconInfModel)->Void)?;
    
    public var onFail:((MTBeacon123Base, ErroCode)->Void)?;
}

// 设置通用参数回调
public class MTBeacon123Base_BaseCallBack: NSObject {
    
    public override init() {
        super.init();
    }
    
    public var onSuccess:((MTBeacon123Base)->Void)?;
    
    public var onFail:((MTBeacon123Base, ErroCode)->Void)?;
}
